package com.phone580.app.model;

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.phone580.app.entity.LoginEntity;

public class LoginModel extends BaseModel{
	
	public LoginEntity parseLogin(String xml) throws ParserConfigurationException, SAXException, IOException {
		LoginEntity entity = new LoginEntity();
//		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//		DocumentBuilder builder = factory.newDocumentBuilder();
//		Document dom = builder.parse(new InputSource(new StringReader(result)));
//		Element root = dom.getDocumentElement();
//		boolean success = Boolean.valueOf(getContent(root, "success"));
//		String message = getContent(root, "message");
//		if (success) {
//			String staffcode = getContent(root, "staffcode");
//			String username = getContent(root, "username");
//			String regionid = getContent(root, "regionid");
//			String regionname = getContent(root, "regionname");
//			String channelid = getContent(root, "channelid");
//			String channelname = getContent(root, "channelname");
//			String operuserid = getContent(root, "operuserid");
//			String permission4S = getContent(root, "permission4S");
//			String userType = getContent(root, "userType");
//			String agentVerImgpkg = getContent(root, "agentVerImgpkg");
//			String mutinstallVerImgpkg = getContent(root, "mutinstallVerImgpkg");
//			String fbspcVerImgpkg = getContent(root, "fbspcVerImgpkg");
//			String fbsmobileVerImgpkg = getContent(root, "fbsmobileVerImgpkg");
//			String state = getContent(root, "state");
//			String auState = getContent(root, "auState");
//			String dl = getContent(root, "dl");
//			String md5 = getContent(root, "md5");
//			
//			entity.setStaffCode(staffcode);
//			entity.setUsername(username);
//			entity.setRegionid(regionid);
//			entity.setRegionname(regionname);
//			entity.setChannelid(channelid);
//			entity.setChannelname(channelname);
//			entity.setOperuserid(operuserid);
//			entity.setPermission4s(permission4S);
//			entity.setUserType(userType);
//			entity.setAgentVerImgpkg(agentVerImgpkg);
//			entity.setMutinstallVerImgpkg(mutinstallVerImgpkg);
//			entity.setFbspcVerImgpkg(fbspcVerImgpkg);
//			entity.setFbsmobileVerImgpkg(fbsmobileVerImgpkg);
//			entity.setState(state);
//			entity.setAuState(auState);
//			entity.setDl(dl);
//			entity.setMd5(md5);
//		}
//		entity.setSuccess(success);
//		entity.setMessage(message);
		Element root = getDomRootElement(xml);
		entity.setSuccess(Boolean.valueOf(getContent(root, "success")));
		entity.setMessage(getContent(root, "message"));
		entity.setResvalue(getContent(root, "resvalue"));
		entity.setOpenuserid(getContent(root, "operuserid"));
		entity.setStaffcode(getContent(root, "staffcode"));
		entity.setUsername(getContent(root, "username"));
		entity.setEmail(getContent(root, "email"));
		return entity;
	}
}
